import request from '@/utils/request'

/**
 * 统计数据
 * @param {*} params 携带参数
 * @returns
 */
export function getOrderCount(params) {
    return request({
        url: "/admin/orders/count",
        method: 'post',
        data: params
    }).then(res => {
        const {dates, finished, payed, refunded, refunding} = res.data;
        return {
            dates: dates || [],
            series: [
                {name: "已完成", data: finished || []},
                {name: "已付款", data: payed || []},
                {name: "已退单", data: refunded || []},
                {name: "退单中", data: refunding || []},
            ].filter(series => series.data.length > 0),
        };
    });
}

/**
 * 退单申请
 * @param {*} orderId
 * @param {*} bodyParams
 * @returns
 */
export function applyRefund(orderId, bodyParams) {
    return request({
        url: `/admin/orders/applyRefund/${orderId}`,
        method: 'put',
        data: bodyParams,
    })
}

/**
 * 订单分页查询
 * @param {*} params
 * @returns
 */
export function ordersPageQuery(params) {
    return request({
        url: "/admin/orders/pageQuery",
        method: 'post',
        data: params
    })
}

/**
 * 创建订单
 * @param {*} params
 * @returns
 */
export function orderCreat(params) {
    return request({
        url: "/admin/orders/add",
        method: 'post',
        data: params
    })
}

/**
 * 订单编辑
 * @param {*} params
 * @returns
 */
export function orderEdit(params) {
    return request({
        url: `/admin/orders/update/${params.orderId}`,
        method: 'put',
        data: params
    })
}

/**
 * 订单关闭
 * @param {*} param
 * @returns
 */
export function orderClose(param) {
    return request({
        url: `/admin/orders/delete/${param}`,
        method: 'delete'
    })
}


export function orderList(params) {
    return request({
        url: "/shopping/orders/orderList", // 确保路径与后端一致
        method: 'get',
        params: params // 使用 params 属性将参数附加到 URL 上
    });
}


export function getOrderDetail(orderId) {
    return request({
        url: `/shopping/orderDetails/${orderId}`,
        method: 'get'
    })
}

export function getStatus(orderId) {
    return request({
        url: `/shopping/orders/getStatus/${orderId}`,
        method: 'get'
    });
}